﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO;
using System.Text;
using System.Security.Permissions;
using System.Data;


public partial class megahealth_MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        fillMenu();
        
    }


    private void fillMenu()
    {

        string menu = "<ul id='topnav' >";
        
        DataSet items = DB.getCategorias();
       
        if (items!= null && items.Tables[0].Rows.Count!=0)
        {  
            
            for (int i = 0; i < items.Tables[0].Rows.Count; i++)
            {

            menu += "<li><a href='categoria.aspx?get=" + items.Tables[0].Rows[i][0].ToString() + "'>" + items.Tables[0].Rows[i][1].ToString() + "</a>";
            DataSet cat = DB.getProductosporCategoria(items.Tables[0].Rows[i][0].ToString());
            if (cat != null && cat.Tables[0].Rows.Count > 0)
            {
                menu += "<ul class='children'>";
                
                for (int j = 0; j < cat.Tables[0].Rows.Count; j++)
                {


                    menu += "<li><a href='producto.aspx?get=" + cat.Tables[0].Rows[j][0].ToString() + "'>" + cat.Tables[0].Rows[j][1].ToString() + "</a></li>";
                }
                menu += "</ul>";
            }
            menu += "</li>";
            
        }
            menu += "</ul>";
          
            Label labelmenu= new Label();
            labelmenu.Text= menu;
            
           
            PMenu.Controls.Add(labelmenu);
    }
    }
}
